package cn.ithers.blog.controller.admin;

import cn.ithers.blog.response.ResponseResult;
import cn.ithers.blog.service.ICommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: zhanghuan
 * @date: 2020/8/28 14:06
 * @description:
 */
@RestController
@Api(value = "评论", tags = "评论")
@RequestMapping("/admin/comment")
public class CommentAdminApi {

    @Autowired
    private ICommentService commentService;


    /**
     * 删除评论
     *
     * @param commentId
     * @return
     */
    @PreAuthorize("@permission.admin()")
    @ApiOperation("删除评论")
    @DeleteMapping("/{commentId}")
    public ResponseResult deleteComment(@ApiParam(value = "评论ID", required = true) @PathVariable("commentId") String commentId) {
        return commentService.deleteComment(commentId);
    }

    /**
     * 获取评论列表
     *
     * @param page
     * @param pageSize
     * @return
     */
    @PreAuthorize("@permission.admin()")
    @ApiOperation("获取评论列表")
    @GetMapping("/list/{page}/{pageSize}")
    public ResponseResult listComments(
            @ApiParam(value = "当前页码", required = true) @PathVariable("page") int page,
            @ApiParam(value = "每页显示条数", required = true) @PathVariable("pageSize") int pageSize) {
        return commentService.listComments(page, pageSize);
    }

    /**
     * 评论置顶
     *
     * @param commentId
     * @return
     */
    @PreAuthorize("@permission.admin()")
    @ApiOperation("评论置顶")
    @PutMapping("/top/{commentId}")
    public ResponseResult topComment(@ApiParam(value = "评论ID", required = true) @PathVariable("commentId") String commentId) {
        return commentService.topComment(commentId);
    }
}
